home *** CD-ROM | disk | FTP | other *** search
- Path: news1.sympatico.ca!news
- From: Gisele Swinson <gisele.swinson@sympatico.ca>
- Newsgroups: comp.lang.c
- Subject: Sorting a Binary File
- Date: 14 Apr 1996 21:15:59 GMT
- Organization: Sympatico
- Message-ID: <4krpuf$jfp@news1.sympatico.ca>
- NNTP-Posting-Host: ppp2022.on.sympatico.ca
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.22MII (Windows; I; 16bit)
-
- I have declared a structure as follows:
-
- #define max 5
-
- struct customer
- {
- int seatno;
- char lastname[15];
- } Customer[max];
-
- I have also initialized the structure as the seat numbers 1-5 and the last
- name as blank
-
- My program summarized is I enter a seat number then enter the name, when I
- cam finished, save the data to a binary file. I want to sort the
- structures in last name order. I tried using bubble sort but I'm not
- being very successful.
-
- This is what I tried:
-
- for(pass=1; pass<max; pass++)
- for(i = 0; i<max-1; i++)
-
- if(Customer[i].lastname > Customer[i+1].lastname)
- {
- temp = Customer[i];
- Customer[i] = Customer[i+1];
- Customer[i+1] = temp;
- }
-
- printf("\nSorted customer list");
- printf("\nSeat number Customer Name"):
-
- for(x=0; x<max; x++)
- printf("\n%2d\t %s", Customer[x].seatno, Customer[x].lastname);
-
-
- I'm sorry this is quite detailed, but I am quit lost as to what I am doing
- wrong.
-
- If anyone can shed some light, I would truly appreciate it.
-
- Thanks
-
- Gisele
-
-
-
-
-